<template>
  <!-- 雷达图  图表必须给高和宽度-->
  <div ref="myDiv" class="radar-echart" />
</template>
<script>
// 按需加载
const echarts = require('echarts/lib/echarts') // 引入echarts主模块
require('echarts/lib/chart/radar') // 引入雷达图
// 引入提示框和标题组件
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
export default {
  data() {
    return {
      radarData: []
    }
  },
  async mounted() {
    await this.getRadarData()
    this.renderRadar()
  },
  methods: {
    // 渲染雷达图
    renderRadar() {
      const myEcharts = echarts.init(this.$refs.myDiv)
      const option = {
        title: {
          text: '员工效率图'
        },
        tooltip: {
          show: true
        },
        radar: {
          indicator: [
            { name: '工作效率', max: 100 },
            { name: '考勤', max: 100 },
            { name: '积极性', max: 100 },
            { name: '帮助同事', max: 100 },
            { name: '自主学习', max: 100 },
            { name: '正确率', max: 100 }
          ]
        },
        series: [
          {
            name: '工作效率',
            type: 'radar',
            // 雷达数据
            data: this.radarData
          }
        ]
      }
      myEcharts.setOption(option)
    },

    // 获取雷达图数据
    getRadarData() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          // 省略数据的处理工作
          const data = [
            {
              value: [10, 1, 100, 5, 100, 0],
              name: '张三'
            },
            {
              value: [50, 50, 50, 50, 50, 10],
              name: '李四'
            }
          ]
          this.radarData = data
          resolve()
        }, 0)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.radar-echart {
  width: 600px;
  height: 400px;
}
</style>
